package java8.chapter05.test;

import static java8.chapter04.test.Dish.menu;

import java.util.Optional;

import java8.chapter04.test.Dish;

public class Finding {

	public static void main(String[] args) {
		if (isVegetarianFriendlyMenu())
			System.out.println("Vegetarian friendly");
		
		System.out.println(isHealthyMenu());
		System.out.println(isHealthyMenu2());
		
		Optional<Dish> dish = findVegetarianDish();
		dish.ifPresent(d -> System.out.println(d.getName()));
	}

	private static Optional<Dish> findVegetarianDish() {
		return menu.stream().filter(Dish::isVegetarian).findAny();
	}

	private static boolean isHealthyMenu2() {
		return menu.stream().noneMatch(d -> d.getCalories() >= 1000);
	}

	private static boolean isHealthyMenu() {
		return menu.stream().allMatch(d -> d.getCalories() < 1000);
	}

	private static boolean isVegetarianFriendlyMenu() {
		return menu.stream().anyMatch(Dish::isVegetarian);
	}

}